package view;

import entity.CourseDO;
import entity.GradeDO;
import handler.AddCourseViewHandler;
import handler.AddGradeViewHandler;

import javax.swing.*;
import java.awt.*;

public class AddGradeView extends JDialog {
    JPanel jPanel = new JPanel();
    //    JLabel snoLabel = new JLabel("学号");
//    JTextField snoTxt = new JTextField();
    JLabel IDLabel = new JLabel("ID");
    JTextField IDTxt = new JTextField();
    JLabel nameLabel = new JLabel("课程号");
    JTextField nameTxt = new JTextField();

    JLabel snoLabel = new JLabel("学号");
    JTextField snoTxt = new JTextField();

    JLabel sexLabel = new JLabel("等级");
    JTextField sexTxt = new JTextField();

    JLabel ageLabel = new JLabel("分数");
    JTextField ageTxt = new JTextField();


    JLabel deptLabel = new JLabel("学期");
    JTextField deptTxt = new JTextField();
    //
//
//    JLabel speLabel = new JLabel("专业");
//    JTextField speTxt = new JTextField();
//
//
//    JLabel sclass = new JLabel("班级");
//    JTextField classTxt = new JTextField();
//
    JButton addBtn = new JButton("添加");

    AddGradeViewHandler addGradeViewHandler;

    public AddGradeView(GradeView gradeView) {
        super(gradeView, "添加信息", true);

        addGradeViewHandler = new AddGradeViewHandler(this, gradeView);

        IDLabel.setPreferredSize(new Dimension(80, 30));
        jPanel.add(IDLabel);
        IDTxt.setPreferredSize(new Dimension(200, 30));
        jPanel.add(IDTxt);

        snoLabel.setPreferredSize(new Dimension(80, 30));
        jPanel.add(snoLabel);
        snoTxt.setPreferredSize(new Dimension(200, 30));
        jPanel.add(snoTxt);

        nameLabel.setPreferredSize(new Dimension(80, 30));
        jPanel.add(nameLabel);
        nameTxt.setPreferredSize(new Dimension(200, 30));
        jPanel.add(nameTxt);


        sexLabel.setPreferredSize(new Dimension(80, 30));
        jPanel.add(sexLabel);
        sexTxt.setPreferredSize(new Dimension(200, 30));
        jPanel.add(sexTxt);

        ageLabel.setPreferredSize(new Dimension(80, 30));
        jPanel.add(ageLabel);
        ageTxt.setPreferredSize(new Dimension(200, 30));
        jPanel.add(ageTxt);

        deptLabel.setPreferredSize(new Dimension(80, 30));
        jPanel.add(deptLabel);
        deptTxt.setPreferredSize(new Dimension(200, 30));
        jPanel.add(deptTxt);

        addBtn.addActionListener(addGradeViewHandler);
//
        jPanel.add(addBtn);

        Container contenPane = getContentPane();
        contenPane.add(jPanel);

        setSize(600, 400);//大小
        setVisible(true);//可以看见
        setResizable(false);//不可变大小
        setDefaultCloseOperation(DISPOSE_ON_CLOSE);//退出自动关闭
        setLocationRelativeTo(null);//居中
    }

    public GradeDO buildGradeDO() {
        GradeDO gradeDO = new GradeDO();
        gradeDO.setId(Integer.valueOf(IDTxt.getText()));
        gradeDO.setSno(Integer.valueOf(snoTxt.getText()));
        gradeDO.setCno(Integer.valueOf(nameTxt.getText()));
        gradeDO.setLevel(sexTxt.getText());
        gradeDO.setGrade(ageTxt.getText());
        gradeDO.setSemester(deptTxt.getText());
        return gradeDO;
    }

}
